package com.b2b2c.store.single.logic;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import javax.servlet.http.HttpServletRequest;

import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;

import com.b2b2c.store.single.entity.Brand;
import com.b2b2c.store.single.mapper.BrandMapper;
import com.b2b2c.store.single.service.IBrandService;

/**
   *     品牌列表
 * @author Administrator
 */
public class BrandLogic extends AbstractLogic<Brand, Object> implements IBrandService<Brand>
{

	public BrandLogic(HttpServletRequest req) {
		super(req);
		// TODO Auto-generated constructor stub
	}

	@Override
	public Map<String, Map<String, String>> getValidateRule() {
		// TODO Auto-generated method stub
		
		Map<String, Map<String, String>> validate = new HashMap<String, Map<String,String>>();
		
		Map<String, String> message = new HashMap<String, String>();
		
		message.put("checkNumber", "id必须是数字");
		
		validate.put("goods_class_id", message);
		
		return validate;
	}
	
	/**
	 * 
	 * @return
	 */
	public List<Brand> getBrandList(RedisTemplate<String, List<Brand>> redisTemplate) {
		
		
		ValueOperations<String, List<Brand>> valueOption =  redisTemplate.opsForValue();
		
		String key =  "brand_cache_me1122";
		
		List<Brand> list = valueOption.get(key);
		
		if(list != null) {
			return list;
		}
		
		List<Brand> brandList = this.getSqlTemp().getMapper(BrandMapper.class).selectAllByStatus();
		
		this.getSqlTemp().clearCache();
		
		if (brandList == null) {
			return brandList;
		}
		
		valueOption.set(key, brandList, 60, TimeUnit.SECONDS);
		
		return brandList;
	}

	

}
